package com.mooue.controller;

import com.fresh.common.ResponseResult;
import com.mooue.entity.Custom;
import com.mooue.service.CustomService;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;

/**
 * 客户表(Custom)表控制层
 *
 * @author bsciology
 * @since 2023-08-09 11:56:35
 */
@RestController
@RequestMapping("custom")
public class CustomController {
    /**
     * 服务对象
     */
    @Resource
    private CustomService customService;

    /**
     * 通过主键查询单条数据
     *
     * @param id 主键
     * @return 单条数据
     */
    @GetMapping("{id}")
    public ResponseResult<Custom> queryById(@PathVariable("id") Integer id) {
        return new ResponseResult<>(200, "ok", this.customService.queryById(id));
    }

    /**
     * 新增数据
     *
     * @param custom 实体
     * @return 新增结果
     */
    @PostMapping
    public ResponseResult<Custom> add(Custom custom) {
        return new ResponseResult<>(200, "ok", this.customService.insert(custom));
    }

    /**
     * 编辑数据
     *
     * @param custom 实体
     * @return 编辑结果
     */
    @PutMapping
    public ResponseResult<Custom> edit(Custom custom) {
        return new ResponseResult<>(200, "ok", this.customService.update(custom));
    }

    /**
     * 删除数据
     *
     * @param id 主键
     * @return 删除是否成功
     */
    @DeleteMapping
    public ResponseResult<Boolean> deleteById(Integer id) {
        return new ResponseResult<>(200, "ok", this.customService.deleteById(id));
    }

}

